﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Bxas.Utility.Convertors
{
   public class TypeConvertors
    {
       private static SqlDbType GetDBType(System.Type theType)
       {
           SqlParameter param;
           System.ComponentModel.TypeConverter tc;
           param = new SqlParameter();
           tc = System.ComponentModel.TypeDescriptor.GetConverter(param.DbType);
           if (tc.CanConvertFrom(theType))
           {
               param.DbType = (DbType)tc.ConvertFrom(theType.Name);
           }
           else
           {
               // try to forcefully convert
               try
               {
                   param.DbType = (DbType)tc.ConvertFrom(theType.Name);
               }
               catch (Exception e)
               {
                   // ignore the exception
               }
           }
           return param.SqlDbType;
       }
    }
}
